package com.bw.tig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.tig.entity.DDetail;
import com.bw.tig.entity.DTigether;
import com.bw.tig.entity.DTigetherReq;
import com.bw.tig.entity.cvEntity;
import com.bw.tig.mapper.DDetailMapper;
import com.bw.tig.mapper.DTigetherMapper;
import com.bw.tig.service.IDTigetherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xingjinning
 * @since 2020-06-10
 */
@Service
public class DTigetherServiceImpl extends ServiceImpl<DTigetherMapper, DTigether> implements IDTigetherService {

    @Autowired
    private DTigetherMapper tigetherMapper;

    @Autowired
    private DDetailMapper detailMapper;

    @Transactional
    @Override
    public void insertCv(cvEntity entitys) {
        if(null==entitys.getTigForms().getId()){
            entitys.getTigForms().setStatus(0);
            tigetherMapper.insertTig(entitys.getTigForms());
        }else{
            tigetherMapper.updateById(entitys.getTigForms());
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("tid",entitys.getTigForms().getId());
        detailMapper.delete(queryWrapper);
        List<DDetail> goodss=entitys.getGoodss();
        for (DDetail goods:goodss ){
            goods.setTid(entitys.getTigForms().getId());
            detailMapper.insert(goods);
        }
    }

    @Override
    public DTigetherReq getMoney() {
        DTigetherReq dTigetherReq=tigetherMapper.getMoney();
        return dTigetherReq;
    }
}
